package com.ruoyi.web.controller.community;


import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.community.domain.CmtDisPeople;
import com.ruoyi.community.service.ICmtDisPeopleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 数据防疫情况信息
 *
 * @author ruoyi
 */
@RestController
@RequestMapping("/community/dis/people")
public class CmtDisController extends BaseController
{
    @Autowired
    private ICmtDisPeopleService iCmtDisPeopleService;

    @PreAuthorize("@ss.hasPermi('community:dis:list')")
    @GetMapping("/list")
    public TableDataInfo list(CmtDisPeople cmtDisPeople)
    {
        startPage();
        List<CmtDisPeople> list = iCmtDisPeopleService.selectDisList(cmtDisPeople);
        return getDataTable(list);
    }


    /**
     * 查询防疫情况类型详细
     */
    @PreAuthorize("@ss.hasPermi('community:dis:query')")
    @GetMapping(value = "/{disId}")
    public AjaxResult getInfo(@PathVariable Long disId)
    {
        return AjaxResult.success(iCmtDisPeopleService.selectDisById(disId));
    }

    /**
     * 新增防疫情况类型
     */
    @PreAuthorize("@ss.hasPermi('community:dis:add')")
    @PostMapping
    public AjaxResult add(@Validated @RequestBody CmtDisPeople dis)
    {

        dis.setCreateBy(SecurityUtils.getUsername());
        return toAjax(iCmtDisPeopleService.insertDis(dis));
    }

    /**
     * 修改防疫情况类型
     */
    @PreAuthorize("@ss.hasPermi('community:dis:edit')")
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody CmtDisPeople dis)
    {

        dis.setUpdateBy(SecurityUtils.getUsername());
        return toAjax(iCmtDisPeopleService.updateDis(dis));
    }

    /**
     * 删除防疫情况类型
     */
    @PreAuthorize("@ss.hasPermi('community:dis:remove')")
    @DeleteMapping("/{disIds}")
    public AjaxResult remove(@PathVariable Long[] disIds)
    {
        iCmtDisPeopleService.deleteDisByIds(disIds);
        return success();
    }



    /**
     * 获取防疫情况选择框列表
     */
    @GetMapping("/optionselect")
    public AjaxResult optionselect()
    {
        List<CmtDisPeople> disPeople = iCmtDisPeopleService.selectDisAll();
        return AjaxResult.success(disPeople);
    }
}
